package model

import (
	"go-devops/domain/dto"
	"sync"
)

type ContextMap struct {
	lock sync.RWMutex
	data map[string]*dto.NodeContext
}

func NewContextMap() *ContextMap {
	return &ContextMap{
		data: make(map[string]*dto.NodeContext),
	}
}

func (c *ContextMap) Get(key string) *dto.NodeContext {
	c.lock.RLock()
	defer c.lock.RUnlock()
	return c.data[key]
}

func (c *ContextMap) Set(key string, value *dto.NodeContext) {
	c.lock.Lock()
	defer c.lock.Unlock()
	c.data[key] = value
}

func (c *ContextMap) Delete(key string) {
	c.lock.Lock()
	defer c.lock.Unlock()
	delete(c.data, key)
}
